<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>知识成果共享平台-注册</title>
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="register.css">
    <style>
        .layui-form-select dl dd.layui-this {
            background-color: #1E9FFF;
            color: #fff;
        }
    </style>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <script type="text/javascript">
        function register(){
            var identity =document.getElementById("identity").value;
            var userId = document.getElementById("username").value;
            var password = document.getElementById("password").value;
            var name = document.getElementById("realname").value;
            console.log(identity,userId,password,name)
            if(identity.length===0||userId.length===0||password.length===0||name.length===0)
            {
                layui.use('layer',function(){
                    var layer=layui.layer;
                    layer.msg('请完善注册信息！',{
                        icon:2,
                        area:['180px','64px'],
                        time:3000
                    });
                });
            }
            else if(userId.length<6||userId.length>6)
            {
                layui.use('layer',function(){
                    var layer=layui.layer;
                    layer.msg('账号填写不规范！',{
                        icon:2,
                        area:['180px','64px'],
                        time:3000
                    });
                });
            }
            else if(userId===6)
            {
                for(var i=0;i<6;i++)
                {
                    if(userId[i]<'0'||userId[i]>'9')
                    {
                        layui.use('layer',function(){
                            var layer=layui.layer;
                            layer.msg('账号填写不规范！',{
                                icon:2,
                                area:['180px','64px'],
                                time:3000
                            });
                        });
                        break;
                    }
                }
            }
            else if(name.length<2||name.length>4)
            {
                layui.use('layer',function(){
                    var layer=layui.layer;
                    layer.msg('真实姓名填写不规范！',{
                        icon:2,
                        area:['180px','64px'],
                        time:3000
                    });
                });
            }
            else {
                $.ajax({
                    url:'http://106.14.215.182:9091/tby/ipos-login/register',
                    data:JSON.stringify({
                        userId:userId,
                        password:password,
                        identity:identity,
                        name:name
                    }),
                    contentType: 'application/json',
                    //返回值类型
                    dataType: 'json',
                    type:'post',

                    success:function(result) {
                        if(result.msg == "SUCCESS"){
                            // alert("注册成功");
                            layui.use('layer',function(){
                                var layer=layui.layer;
                                layer.msg('注册成功！',{
                                    icon:1,
                                    area:['180px','64px'],
                                    time:3000
                                },function () {
                                    window.location = 'login.html';
                                });
                            });
                        }else{
                            // alert(result.data);
                            layui.use('layer',function(){
                                var layer=layui.layer;
                                layer.msg(result.data,{
                                    icon:2,
                                    area:['180px','64px'],
                                    time:3000
                                });
                            });
                        }
                    }
                })
            }
        }
    </script>
</head>
<body>
<div class="layui-container">
    <div class="admin-login-background">
        <div class="layui-form login-form">
            <form class="layui-form" action="">
                <div class="layui-form-item logo-title">
                    <h1>欢迎注册知识成果共享平台</h1>
                </div>
                <div class="layui-input-inline" style="width: 458px;margin-bottom: 20px">
                    <select id="identity" name="quiz2">
                        <option value="">请选择身份</option>
<!--                        <option value="访客">访客</option>-->
                        <option value="学生" >学生</option>
                        <option value="辅导员">辅导员</option>
                        <option value="班导师">班导师</option>
                        <option value="自动化教师">自动化教师</option>
                        <option value="软件工程教师">软件工程教师</option>
                        <option value="管理员">管理员</option>
                    </select>
                </div>
                <div class="layui-form-item" >
                    <label class="layui-icon layui-icon-username"></label>
                    <input type="text" id="username" lay-verify="required|account" placeholder="账号" autocomplete="off"
                           class="layui-input">
                </div>
                <div class="layui-form-item">
                    <label class="layui-icon layui-icon-password"></label>
                    <input type="password" id="password" lay-verify="required|password" placeholder="密码"
                           autocomplete="off" class="layui-input">
                </div>
                <div>
                    <div class="layui-form-item">
                        <input type="text" id="realname" lay-verify="required|password" placeholder="请输入您的姓名"
                               autocomplete="off" class="layui-input" >
                    </div>
                </div>
                <div class="layui-form-item">
                    <button type="button" class="layui-btn layui-btn layui-btn-normal layui-btn-fluid" lay-submit="" onclick="register()"
                            lay-filter="register">注 册
                    </button>
                </div>
                <div>
                    已有账号？立即<a href="login.html">登录</a>
                </div>
            </form>
        </div>
    </div>
</div>
<div>
    <img src="temp.jpg" alt="">
</div>

<script type="text/javascript" src="../layui/layui.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer;

    });
</script>
</body>
</html>